const app = getApp()
Page({
  data: {
    site:[], // 所有的地址
    userSite:[], // 用户选择的地址
    home:'',
    SubmitHidden:true // 确认按钮的默认显示状况
  },
  onLoad: function (options) {
    this.setData({
      home : options.datas
    })
    this.getSite()
  },
  getSite(){
    let that = this
    wx.request({
      url: 'http://localhost:8081/interfaced/address/list',
      success(data){
        // data.data.rows[0].ins = true // 取消默认选择第一个
        that.setData({
          site : data.data.rows
        })
      }
    })
  },
  siteadd(){
    wx.reLaunch({
      url: '../siteAdd/index',
    })
  },
  siteMain(data){
    data = data.currentTarget.dataset.a
    let item; 
    for(let a=0;a<this.data.site.length;a++){
      item = "site["+a+"].ins"
      this.setData({
        [item] : false
      })
    }
    item = "site["+data+"].ins"
    this.setData({
      [item] : true,
      SubmitHidden : false,
      userSite : this.data.site[data]
    })

  },
  homes(){
    app.globalData.user.site = this.data.userSite
    let urls = "/pages/"+this.data.home+"?name=tack"
    wx.reLaunch({
      url: urls,
    })
  }
})